<!-- ForgetPasswordPc -->
<template>
  <div class="ForgetPasswordPc">
    <div class="loginHeader">
      <div class="loginBox">
        <div class="loginLeft">
          <img src="./../../../assets/img/navbar/logo.png" class="logoImg" @click="goHome"/>
          <div class="heightStyle"></div>
          <div class="loginName">一站式智能机械服务平台</div>
        </div>
        <div class="loginTitle">
          <div @click="goHome" class="goHome">返回首页</div>
            <div class="titleName">想起密码，现在去</div>
            <div class="goLogin" @click="goLogin">登录</div>
        </div>
      </div>
    </div>
    <div class="bodyBox">
      <div class="loginRegion">
        <div class="logincontainer">
          <div class="headerStyle">忘记密码</div>
          <div class="inputBox">
            <div class="inputItem">
              <div class="itemInput1">
                <span class="inputLeftNum">+86</span>
                <input type="text" v-model="userPhone" placeholder="请输入手机号码" class="inputClass" maxlength="11" @focus='noPhone'>
              </div>
              <!-- <div>
               <img src="./../../../assets/img/login/groupIcon.png" class="groupIcon" v-if="userPhone.length=='11'"/>
               <div class="successBox" v-if="isPhone">
               <img src="./../../../assets/img/login/success.png" class="success"/>
               <span class="successName" v-if="isPhone" ref="isPhone">{{isPhone}}</span>
               </div>
              </div> -->
            </div>
            <div class="inputItem3">
              <div class="itemInput">
              <input type="text" placeholder="请输入您的短信验证码" class="inputClass2" v-model="userCode" maxlength="6" @focus="noCode">
              <span class="inputCode" v-show="sendAuthCode" @click="getAuthCode">获取短信验证码</span>
              <span class="inputCode" v-show="!sendAuthCode">
                  <span>{{ auth_time }}</span>发送验证码
              </span>
              </div>
              <div class="successBox2" v-if="isCode">
               <img src="./../../../assets/img/login/success.png" class="success"/>
               <span class="successName" v-if="isCode">{{isCode}}</span>
              </div>
            </div>
            <div class="inputItem1">
              <div class="itemInput">
              <input :type="pwdType" placeholder="请设置您的登录密码" v-model="userPawss" class="inputClass1" @focus="noPawss">
              <img src="./../../../assets/img/login/pawassIcon.png" class="pawassIcon" v-if="userPawss" @click="showPwd"/>
              </div>
              <div class="successBox1" v-if="isPawss">
               <img src="./../../../assets/img/login/success.png" class="success"/>
               <span class="successName" v-if="isPawss" ref="isPawss">{{isPawss}}</span>
              </div>
            </div>
            <div class="inputItem1">
              <div class="itemInput">
              <input :type="pwdType1" placeholder="请再次输入您的密码" v-model="userPawssTwo" class="inputClass1" @focus="noPawssTwo">
              <img src="./../../../assets/img/login/pawassIcon.png" class="pawassIcon" v-if="userPawssTwo" @click="showPwd1"/>
              </div>
              <div class="successBox1" v-if="isPawssTwo">
               <img src="./../../../assets/img/login/success.png" class="success"/>
               <span class="successName" v-if="isPawssTwo">{{isPawssTwo}}</span>
              </div>
            </div>
          </div>
          <div class="sunBtn" @click="returnLogin">确认</div>
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="footer_name">
        <ul class="footerNameList">
          <li>关于我们</li>
          <li>法律声明</li>
          <li>用户协议</li>
          <li>联系我们</li>
          <li>合作伙伴</li>
        </ul>
        <div class="footerNameBotom">
          <div>
            Copyright © 2015-2020 轰隆隆honglonglong. All Rights Reserved
          </div>
          <div>京ICP备15045098号</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script >
const msgTime = 59;
import { getForgetpassworduc, getSendCode } from "./../../../apis/api.js";
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      userPhone:'',//手机号码
      userPawss:'',//密码
      userPawssTwo:'',//密码1
      userCode:'',//短信验证码
      pwdType: "password",
      pwdType1: "password",
      sendAuthCode: true,
      auth_time: msgTime,
      resendTimer: null,
      isPhone:false,//手机提示
      isPawss:false, //密码提示
      isPawssTwo:false,//密码提示1
      isCode:false,//验证码提示
    };
  },
  // 过滤器
  filters: {},
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 跳转首页
    goHome(){
      this.$router.push({path:'/homePc'})
    },
    goLogin(){
      this.$router.push({path:'/LoginPc'})
    },
    // 手机号校验
    varifyPhoneNum(phoneNum) {
      if (!phoneNum) return false;
      let myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
      if (!myreg.test(phoneNum)) {
        return false;
      } else {
        return true;
      }
    },
   // 获取验证码
    async getAuthCode() {
      if(this.userPhone == ''||this.userPhone == undefined){
          this.isPhone = this.$refs.isPhone ='请填写手机号码！'
          return
       }
      let base64phoneNumber = this.userPhone;
      if (!this.varifyPhoneNum(this.userPhone)) {
        this.isPhone = true;
        return false;
      }
      this.sendAuthCode = false;
      let params = {
        phone: base64phoneNumber,
      };
      try {
        let res = await getSendCode(params);
        this.resendTimer = setInterval(() => {
          this.auth_time--;
          if (this.auth_time <= 0) {
            this.sendAuthCode = true;
            this.auth_time = msgTime;
            clearInterval(this.resendTimer);
          }
        }, 1000);
        if (res.data.result === 1) {
          this.$message.success("验证码已发送！");
        } else {
          this.$message.error(res.data.message);
        }
      } catch (e) {
        this.resendTimer = setInterval(() => {
          this.auth_time--;
          if (this.auth_time <= 0) {
            this.sendAuthCode = true;
            this.auth_time = msgTime;
            clearInterval(this.resendTimer);
          }
        }, 1000);
      }
    },
    // 提交修改密码
     async returnLogin(){
       console.log(this.isPawssTwo)
       console.log(this.userPawssTwo)
       if(this.userPhone == ''||this.userPhone == undefined){
          this.isPhone = this.$refs.isPhone ='请填写手机号码！'
          return
       }
       if(this.userPawss == ''||this.userPawss == undefined){
          this.isPawss = this.$refs.isPawss = '请填写密码！'
          return
       }
       if(this.userPawssTwo == ''||this.userPawssTwo == undefined){
          this.isPawssTwo = this.$refs.isPawssTwo = '请再次填写密码！'
          return
       }
      //   if(this.userPawssTwo != this.userPawss ){
      //     this.isPawssTwo = this.$refs.isPawssTwo = '密码不一致，请确认输入密码！'
      //     return
      //  }
       if(this.userCode == ''||this.userCode == undefined){
          this.isCode = this.$refs.isCode = '请填写验证码！'
          return
       }
        let params = {
          pwd:this.userPawss,
          new_pwd:this.userPawssTwo,
          phone:this.userPhone,
          code:this.userCode
        }
        let res = await getForgetpassworduc(params)
        if(res.data.result == '1'){
          console.log(res)
          setTimeout(()=>{
            this.$router.push({path:'./loginPc'})
          },1500)
          this.$message.success('密码设置成功！')
        }
        if(res.data.result == '104'){
          this.isPhone = this.$refs.isPhone ='手机号码错误！'
        }
        if(res.data.result == '101'){
          this.isPawss = this.$refs.isPawss = '登录密码格式错误'
        }
        if(res.data.result == '102'){
          this.isPawssTwo = this.$refs.isPawssTwo = '两次密码不一致'
        }
        if(res.data.result == '103'){
          this.isCode = this.$refs.isCode = '验证码不正确！'
        }
    },
    // 星号显示密码
    showPwd() {
      if (this.pwdType === "password") {
        this.pwdType = "";
      } else {
        this.pwdType = "password";
      }
    },
    // 星号显示密码
    showPwd1() {
      if (this.pwdType1 === "password") {
        this.pwdType1 = "";
      } else {
        this.pwdType1 = "password";
      }
    },
    // input进入焦点
    noPhone(){
      this.isPhone = this.$refs.isPhone =''
    },
    noPawss(){
      this.isPawss = this.$refs.isPawss =''
    },
    noPawssTwo(){
      this.isPawssTwo = this.$refs.isPawssTwo =''
    },
    noCode(){
      this.isCode = this.$refs.isCode =''
    },
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  ctivated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>

<style lang='scss' scoped>
.ForgetPasswordPc{
  box-sizing: border-box;
  background: #1f2327;
}
.loginHeader {
  width: 100%;
  height: 56px;
  line-height: 56px;
  background: #fff;
}
.logoImg {
  width: 105px;
  height: 36px;
  cursor: pointer;
}
.heightStyle {
  width: 1px;
  height: 27px;
  background: #c0c4cc;
  margin-left: 31px;
  margin-right: 28px;
}
.goHome {
  cursor: pointer;
  font-size: 16px;
  color: #333333;
  text-decoration: underline;
}
.loginBox {
  margin: 0 130px;
  display: flex;
  justify-content: space-between;
}
.loginLeft {
  display: flex;
  align-items: center;
}
.loginName {
  font-size: 18px;
  color: #49535c;
}
.footer {
  border-top: 1px solid #ccc;
  width: 100%;
  height: 140px;
}
.footer_name {
  display: flex;
  text-align: center;
  flex-direction: column;
  margin-top: 25px;
}
.footerNameList {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  li {
    width: 100px;
  }
}
.footerNameBotom {
  margin-top: 18px;
  font-size: 14px;
  color: #c0c4cc;
}
.bodyBox {
  width: 100%;
  height: 87vh;
}
.loginRegion {
  display: flex;
  justify-content: space-evenly;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.logincontainer{
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 628px;
  height: 400px;
  background: #FFFFFF;
}
.loginTitle{
  display: flex;
  align-items: center;
}
.titleName{
  margin-left: 10px;
  font-size: 16px;
  color: #333;
}
.goLogin{
  margin-left: 10px;
  color:#FF7D59;
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
}
.headerStyle{
  width: 100%;
  height: 68px;
  line-height: 68px;
  color: #fff;
  font-size: 24px;
  background: #484E61;
  text-align: center;
}
.inputItem{
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.inputItem1{
  display: flex;
  align-items: center;
  position: relative;
}
.inputItem3{
  display: flex;
  align-items: center;
  position: relative;
  margin-bottom: 20px;
}
.itemInput{
  display: flex;
  align-items: center;
}
.itemInput1{
  display: flex;
}
.pawassIcon{
  width: 16px;
  height: 16px;
  position: absolute;
  top: 10px;
  right: 255px;
  cursor: pointer;
}
.successBox{
  display: flex;
  align-items: center;
  margin-top: -20px;
}
.successBox1{
  display: flex;
  align-items: center;
  margin-top: -20px;
}
.successBox2{
  display: flex;
  align-items: center;
  margin-top: -5px;
}
.success{
  width: 14px;
  height: 14px;
  margin-left: 10px;
}
.successName{
  font-size:12px;
  color: #F56C6C;
  margin-left: 10px;
}
.inputLeftNum{
  width: 40px;
  height: 34px;
  line-height: 34px;
  text-align: center;
  border-top: 1px solid #D7D7D7;
  border-left: 1px solid #D7D7D7;
  border-bottom: 1px solid #D7D7D7;
  font-size: 12px;
  color: #bbb;
}
.inputClass{
  width: 280px;
  height: 34px;
  border: 1px solid #D7D7D7;
  color: #333;
  font-size: 12px;
  padding-left: 10px;
}
.inputClass1{
  width: 320px;
  height: 34px;
  border: 1px solid #D7D7D7;
  color: #333;
  font-size: 12px;
  padding-left: 10px;
  margin-bottom: 20px;
}
.inputClass2{
  width: 170px;
  height: 34px;
  background: #FFFFFF;
  border: 1px solid #D7D7D7;
  padding-left: 10px;
  // margin-top: 20px;
}
::-webkit-input-placeholder {
    color: #bbb;
     font-size:12px;
}
 
::-moz-placeholder {
    color: #bbb;
    font-size:12px;
  }
 
:-ms-input-placeholder {
    color: #bbb;
    font-size:12px;
  }
 
  :-moz-placeholder {
    color: #bbb;
    font-size:12px;
  }
  .inputBox{
    margin-top: 29px;
  }
  .inputCode{
    width: 140px;
    line-height: 38px;
    height: 38px;
    background: #fff5f3;
    font-size: 12px;
    color: #FF855B;
    text-align: center;
    margin-left: 10px;
    cursor: pointer;
  }
  .sunBtn{
  width: 330px;
  height: 40px;
  line-height: 40px;
  background: linear-gradient(136deg, #FFB492 0%, #FF7D59 100%);
  border-radius: 4px;
  font-size: 14px;
  color: #fff;
  text-align: center;
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translate(-50%,-50%);
  cursor: pointer;
  }
  .groupIcon{
    width: 18px;
    height: 18px;
    margin-left: 8px;
  }
</style>
